/*    This file is part of nit.
 *
 *    Nit is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    Nit is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public License
 *    along with nit.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef LIST_H
#define LIST_H

#include <stdlib.h>

#include "err.h"
#include "dispose.h"

#define list_foreach(entry, list)			\
	for ((entry) = (list)->head; (entry);		\
	     (entry) = (entry)->next)

typedef struct List_entry List_entry;

struct List_entry {
	void *data;
        List_entry *next;
};

typedef struct List {
	Disposer *disposer;
	size_t len;
	List_entry *head;
	List_entry *tail;
} List;

void
list_init(List *list, Disposer *disposer);

void
list_dispose(List *list);

Nit_error
list_add(List *list, List_entry *prev, const void *data);

Nit_error
list_remove(List *list, List_entry *prev, void **data);

void **
list_peek(List *list);

#endif
